﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;

namespace HRM.UI.HRManagerUI.EmpModule
{
    public partial class DeleteEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                alldeleteemployee.Visible = false;

            }

        }
        protected void SearchEmployee(object o, EventArgs e)
        {
            try
            {
                Code code = new Code();
                code.CodeName = txtEmpCode.Value;
                EmployeeManager manager = new EmployeeManager();
                ViewEmployee viewEmployee = new ViewEmployee();
                viewEmployee = manager.SearchEmployeeByCode(code);
                if (viewEmployee.Employee.Name != null)
                {
                    alldeleteemployee.Visible = true;   //total div for visible area
                    txtEmpID.Text = code.CodeName;
                    empImage.ImageUrl = viewEmployee.Photo.FileName;
                    txtName.Text = viewEmployee.Employee.Name + ("-");
                    txtFname.Text = viewEmployee.Employee.FathersName;
                    txtMname.Text = viewEmployee.Employee.MothersName;
                    txtSex.Text = viewEmployee.Employee.Sex;
                    txtBlood.Text = viewEmployee.Employee.Blood;
                    txtDob.Text = (viewEmployee.Employee.DOB).ToShortDateString();
                    txtEmail.Text = viewEmployee.Employee.Email;
                    txtnationality.Text = viewEmployee.Employee.Nationality;
                    txtNationalID.Text = viewEmployee.Employee.NID;
                    txtEducation.Text = viewEmployee.Employee.Education;
                    txtDesignation.Text = viewEmployee.Designation.Title;
                    txtSkill.Text = viewEmployee.Employee.Skill;
                    txtJoiningDate.Text = (viewEmployee.Employee.JoiningDate).ToShortDateString();
                    txtContatFinishDate.Text = (viewEmployee.Employee.ContractFinishDate).ToShortDateString();
                    txtProject.Text = viewEmployee.Project.ProjectName;
                    txtCatagory.Text = viewEmployee.Catagory.EmpCatagory;
                    txtStatus.Text = viewEmployee.Employee.Status;
                    msgLbl.Visible = false;
                }
                else
                {
                    msgLbl.Visible = true;
                    msgLbl.ForeColor = Color.Red;
                    msgLbl.Font.Bold = true;
                    msgLbl.Text = "Employee Not Found by this code:" + code.CodeName;
                }
            }
            catch (Exception ex)
            {

                ;
            }

        }

        protected void BtnDeleteEmployee(object sender, EventArgs e)
        {

            try
            {
                Code code = new Code();
                code.CodeName = txtEmpCode.Value;
                EmployeeManager manager = new EmployeeManager();
                Employee employee = new Employee();
                employee.EmpCode = code;
                manager.DeleteEmployee(employee);

                if (manager.DeleteEmployee(employee))
                {
                    msgLbl.Text = "Data Deleted for" + code.CodeName + "Successfully";
                    msgLbl.ForeColor = Color.Green;
                }
                else
                {
                    msgLbl.Text = "Sorry ! Can not be deleted.";
                    msgLbl.ForeColor = Color.Red;
                }


            }
            catch (Exception)
            {
                msgLbl.Text = "Sorry ! Can not be deleted.";
                msgLbl.ForeColor = Color.Red;

            }



        }
    }
}